package de.g18.gruppe3.gui.view;

import java.awt.BorderLayout;
import java.awt.GraphicsEnvironment;
import java.awt.GridLayout;

import javax.swing.*;

public class UMLoginView extends JFrame {
	
	/**
	 * Login Screen des Programms.
	 * Stellt sicher das nur ein Benutzer mit ausreichenden Rechten das AD bearbeiten darf.
	 * Die View nimmt hierzu Loginname und Passwort entgegen.
	 *
	 * @author <a href="madmakro@gmx.net">Jan Schwart</a>
	 */
	
	private static final long serialVersionUID = 1001L;
	private JPanel pUCLoginViewMain = new JPanel();
	private JPanel pUCLoginViewTop = new JPanel();
	private JPanel pUCLoginViewBottom = new JPanel();
	private JLabel lUCLoginViewLogin = new JLabel("Loginname: ");
	private JLabel lUCLoginViewPasswort = new JLabel("Passwort: ");
	private JTextField tfUCLoginViewLogin = new JTextField();
	private JPasswordField pfCLoginViewPasswort = new JPasswordField();
	
	private JButton bUCLoginOk = new JButton("OK");
	private JButton bUCLoginChancel = new JButton("Abbrechen");
	
	//Konstruktor
	public UMLoginView(String title) {
		super(title);
		initializeComponents();
		
	    setDefaultCloseOperation(EXIT_ON_CLOSE);
	    
	    setLayout(new BorderLayout());
	    setSize(256, 144);
	    setLocation(GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().x-(getWidth()/2),
	    			GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().y-(getHeight()/2));
	    setResizable(false);
	    setVisible(true);
	    
	    add(pUCLoginViewMain, BorderLayout.NORTH);
	    add(pUCLoginViewBottom, BorderLayout.SOUTH);
				
	}
	
	//Initialisierung der GUI-Komponenten
	private void initializeComponents() {
		
		//Top Panel:
		pUCLoginViewTop.setLayout(new GridLayout(2, 2, 6, 6));
		pUCLoginViewTop.setBorder(BorderFactory.createTitledBorder("Anmelden"));
		pUCLoginViewTop.add(getlUCLoginViewLogin());
		pUCLoginViewTop.add(gettfUCLoginViewLogin());
		pUCLoginViewTop.add(getlUCLoginViewPasswort());
		pUCLoginViewTop.add(getpfCLoginViewPasswort());
		
		//Bottom Panel:
		pUCLoginViewBottom.setLayout(new GridLayout(1, 2));
		pUCLoginViewBottom.add(getbUCLoginOk());
		pUCLoginViewBottom.add(getbUCLoginChancel());
		
		//Main Panel:
		pUCLoginViewMain.setLayout(new GridLayout());
		pUCLoginViewMain.setBorder(BorderFactory.createEmptyBorder(8, 12, 4, 12));
		pUCLoginViewMain.add(pUCLoginViewTop);
		
	}

	//Getter & Setter
	
	public JLabel getlUCLoginViewLogin() { return lUCLoginViewLogin; };
	public JLabel getlUCLoginViewPasswort() { return lUCLoginViewPasswort; };
	
	public JTextField gettfUCLoginViewLogin() { return tfUCLoginViewLogin; };
	public JPasswordField getpfCLoginViewPasswort() { return pfCLoginViewPasswort; };
	
	public JButton getbUCLoginOk() { return bUCLoginOk; };
	public JButton getbUCLoginChancel() { return bUCLoginChancel; };
	
}
